package com.oa.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.oa.android.R;
import com.oa.android.entry.VoteTp;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by zouqh on 2016/6/17.
 */
public class TPAdapter extends BaseAdapter {

    private Context context;
    private List<VoteTp> tpList;

    public TPAdapter(Context context, List<VoteTp> tps) {
        this.context = context;
        this.tpList = tps;

    }

    @Override
    public int getCount() {
        return tpList.size();
    }

    @Override
    public Object getItem(int position) {
        return tpList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.vote_item, null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        VoteTp voteTp=tpList.get(position);
        viewHolder.name.setText(voteTp.getName());
        viewHolder.number.setText(voteTp.getNumber()+"");
        viewHolder.toup.setChecked(voteTp.isSelect());
        if (voteTp.isSelect()){
            viewHolder.toup.setText("已投");
        }else{
            viewHolder.toup.setText("投票");
        }
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.name)
        TextView name;
        @InjectView(R.id.number)
        TextView number;
        @InjectView(R.id.toup)
        CheckBox toup;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
